'use strict'

const titbit = require('titbit')

const app = new titbit({
  debug: true
})

app.use(async (c, next) => {

  if (!c.query.passkey || c.query.passkey !== '123456') {
    c.res.body = 'permission deny'
    return
  }

  console.log(c.path, 'start')
  await next()
  console.log(c.path, 'end')

})

app.get('/', async c => {
  c.res.body = 'success'
})

app.get('/test', async c => {
  c.res.body = Date.now()
})


app.use(async (c, next) => {
  console.log('set max body')
  //设置最大提交允许10字节
  c.maxBody = 10
  await next()

  //设置pre为true等效于使用app.pre，提供method指定针对哪些请求方法执行
}, {pre : true, method : ['POST','PUT']})

app.post('/test', async c => {
  //返回提交的数据
  c.res.body = c.body
})

app.run(1234)
